<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
<!--    <script src="js/vue.js"></script>-->
    <script src="js/jquery-3.3.1.js"></script>
    <script src="js/bootstrap.min.js"></script>

</head>
<style>
    img{
        width: 242px;
        height: 200px;
        margin-right: 10px;
        object-fit: cover;
    }

</style>
<body>
<!--导航栏-->
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="index.html">首页</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li><a href="#">当前类型:</a></li>
                <li><a href="#" id="typename">篮球</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">图片类型 <span class="caret"></span></a>
                    <ul class="dropdown-menu" id="types">

                    </ul>
                </li>
            </ul>
            <div action="#" class="navbar-form navbar-left">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="Search" id="search">
                </div>
                <button class="btn btn-default" onclick="mySearch()">搜索</button>
            </div>
            <ul class="nav navbar-nav navbar-right">
                <li id="userpic"></li>
                <li style="border-right:1px solid silver;"><a href="#">用户名:</a></li>
                <li ><a href="#" id="name1" onclick="gotoMySelf()">请登录</a></li>
                <!--<li class="dropdown">-->
                    <!--<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>-->
                    <!--<ul class="dropdown-menu">-->
                        <!--<li><a href="#">Action</a></li>-->
                        <!--<li><a href="#">Another action</a></li>-->
                        <!--<li><a href="#">Something else here</a></li>-->
                        <!--<li role="separator" class="divider"></li>-->
                        <!--<li><a href="#">Separated link</a></li>-->
                    <!--</ul>-->
                <!--</li>-->
                <li id="regBtn1">
                    <button  class="btn btn-default" data-toggle="modal" data-target="#regModal">注册</button>
                </li>
                <li id="logBtn1">
                    <button  class="btn btn-default" data-toggle="modal" data-target="#logModal">登录</button>
                </li>
            </ul>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>


<!--放主页图片的容器-->
<div class="row">
    <div class="col-md-9" role="main" style="border-right:1px solid silver;">
        <div class="row" id="imgs">


        </div>
        <hr>
        <div style="text-align: center;">
            <nav aria-label="Page navigation">
                <ul class="pagination pagination-lg" id="skips">
<!--                    <li>-->
<!--                        <a href="#" aria-label="Previous" onclick="" id="skippre">-->
<!--                            <span aria-hidden="true">&laquo;</span>-->
<!--                        </a>-->
<!--                    </li>-->
<!--                    <li><a id="skip1" href="#" onclick="">1</a></li>-->
<!--                    <li><a id="skip2" href="#" onclick="">2</a></li>-->
<!--                    <li><a id="skip3" href="#" onclick="">3</a></li>-->
<!--                    <li><a id="skip4" href="#" onclick="">4</a></li>-->
<!--                    <li><a id="skip5" href="#" onclick="">5</a></li>-->
<!--                    <li>-->
<!--                        <a id="skipnex" href="#" aria-label="Next" onclick="">-->
<!--                            <span aria-hidden="true">&raquo;</span>-->
<!--                        </a>-->
<!--                    </li>-->
                </ul>
            </nav>
            <style>
                .c{
                    display:inline;
                }
            </style>
            <div style="text-align: center">
                <input  class="form-control c" type="number"style="width:60px;" id="toPageNum">
                <button class="btn btn-default" id="toPageBtn" onclick="skipToPage()">跳转</button>
            </div>
            <h4>当前页数<span class="label label-default" id="curpage"></span></h4>
        </div>
        <div style="text-align: center;"><a href="#" onclick="gotoAdmin()">Admin</a></div>
        <div style="text-align: center;"><span>官方邮箱: wsq981027@163.com</span></div>
</div>

    <!--上传图片-->
    <div class="col-md-3" role="complementary">
        <div class="form-horizontal" style="border-bottom: 1px solid silver">
            <div class="form-group">
                <label for="pic" class="col-sm-2 control-label">标题</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="title" name="title">
                    <div id="uploadTitleEr"></div>
                </div>
            </div>
            <div class="form-group">
                <label for="pic" class="col-sm-2 control-label">简介</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="intro" name="intro">
                </div>
            </div>
            <div class="form-group">
                <label for="imgtypes" class="col-sm-2 control-label">类型</label>
                <div class="col-sm-10">
                    <select class="form-control" id="imgtypes">

                    </select>
                </div>
            </div>
            <div class="form-group">
                <label for="imgtypes" class="col-sm-2 control-label">标签</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="tags" name="tags">
                    <h5>(注:多个标签请用空格分隔)</h5>
                </div>
            </div>
            <div class="form-group">
                <label for="pic" class="col-sm-2 control-label">图片</label>
                <div class="col-sm-10">
                    <input type="file" class="form-control" id="pic" name="pic">
                    <div id="uploadImgEr"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button class="btn btn-default c" onclick="upload()">上传</button>
                    <div id="uploadEr"></div>
                    <h5>(注:请在登录后上传)</h5>
                </div>
            </div>
        </div>
        <br>
        <h3 style="text-align: center" id="rightTitle">点赞排行</h3>
        <div id="rightDiv">
            <table id="imgs2" class="table table-hover">

            </table>
        </div>
    </div>
</div>

<!--模态框-->
<div class="modal fade" id="regModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                注册
            </div>
            <div class="modal-body">
                账号: <input type="text" class="form-control" name="name" id="regName">
                <div id="erRegName"></div>
                密码：<input type="password" class="form-control" name="password" id="regPass1">
                <div id="erRegPass"></div>
                确认密码: <input type="password" class="form-control" name="password" id="regPass2">
                <div id="erRegPass2"></div>
            </div>
            <div class="modal-footer">
                <button id="btn2" class="btn btn-default" onclick="reg()">注册</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="logModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                登录
            </div>
            <div class="modal-body">
                账号: <input type="text" class="form-control" name="name" id="name">
                <div id="erLogName"></div>
                密码：<input type="password" class="form-control" name="password" id="password">
                <div id="erLogPass"></div>
            </div>
            <div class="modal-footer">
                <button id="btn1" class="btn btn-default" onclick="login()">登录</button>
            </div>
        </div>
    </div>
</div>
</body>
<script src="js/checkToken.js"></script>
<script type="text/javascript">
    var userid=sessionStorage.getItem('id');
    var points=0;

    var pages=0;

    $("#search").bind("keypress", function(){
        if (event.keyCode == 13){
            // 触发需要调用的方法
            mySearch();
        }
    })

    $("#regModal").bind("keypress", function(){
        if (event.keyCode == 13){
            // 触发需要调用的方法
            reg();
        }
    })

    $("#logModal").bind("keypress", function(){
        if (event.keyCode == 13){
            // 触发需要调用的方法
            login();
        }
    })
    document.oncontextmenu = function(){
        return false;
    }

if (sessionStorage.getItem('id')!=null) {
    $.ajax({
        url: '/hui/TestController/getPoints.do?userid=' + userid,
        async: false,
        headers: {
            accessToken: localStorage.getItem('accessToken')
        },
        success: function (datas) {
            checkToken(datas);
            points = datas.result.point;
        }
    })
}

var curpage=sessionStorage.getItem('page');
console.log('当前页数：'+curpage);
curpage=curpage==null?1:curpage;
$('#toPageNum').val(curpage);

    var type='img';
    var search='';


    sessionStorage.setItem('page',1);
    document.getElementById('curpage').innerText=sessionStorage.getItem('page');
    var curtype=2;
    console.log('当前page=',sessionStorage.getItem('page'));
    console.log(sessionStorage.getItem('pic'));
    var name=sessionStorage.getItem('name');
    var userpic=sessionStorage.getItem('pic');
    // alert(userid);
    // console.log('name='+name);
    if(name!='null') {
        document.getElementById('userpic').innerHTML='积分:'+points+'<img class="img-circle" src="/'+userpic+'" alt="" style="width: 50px;height: 50px">';
        document.getElementById('name1').innerText = name;
        document.getElementById('logBtn1').innerHTML='<button class="btn btn-default" onclick="gotoMySelf()">主页</button>';
    }


    $.ajax({
        url: '/hui/TestController/getImgsByType.do?typeid=' + curtype,
        success: function (data) {
            skipPages(data.result.length);
        }
        })
    function skipPages(dataLength) {
                pages = parseInt(dataLength / 12);
                if (dataLength % 12 != 0)
                    pages += 1;
                console.log('页数是:' + pages);
                var loop = pages;
                loop = loop > 5 ? 5 : loop;
                console.log('循环次数是:' + pages);
                for (var i = 0; i < loop; i++) {
                    if (i == 0) {
                        $('#skips').append("                    <li><a id='skip" + i + "' href='#' onclick='skipReady(1)'>first</a></li>"+
                        "<li>\n" +
                            "                        <a href=\"#\" aria-label=\"Previous\" onclick='skipReady(-1)' id=\"skippre\">\n" +
                            "                            <span aria-hidden=\"true\">&laquo;</span>\n" +
                            "                        </a>\n" +
                            "                    </li>\n");
                    }

                    $('#skips').append(
                        "                    <li><a id='skip" + i + "' href='#' onclick='skipReady(" + (i + 1) + ")'>" + (i + 1) + "</a></li>"
                    );
                    if (i == loop - 1) {
                        if (pages > 5) {
                            $('#skips').append(
                                "<li><a>...</a></li>" +
                                "                    <li><a id='skip" + pages + "' href='#' onclick='skipReady(" + pages + ")'>" + pages + "</a></li>")
                        }

                        $('#skips').append(
                            "                    <li>\n" +
                            "                        <a id=\"skipnex\" href=\"#\" aria-label=\"Next\" onclick='skipReady(0)'>\n" +
                            "                            <span aria-hidden=\"true\">&raquo;</span>\n" +
                            "                        </a>\n" +
                            "                    </li>"+
                        "<li><a id='skip" + i + "' href='#' onclick='skipReady("+pages+")'>end</a></li>");
                    }
                }
    }


    function skipReady(page){
        skip(type,page);
    }

    // document.getElementById('skippre').onclick=function () { skip("img",-1); };
    // document.getElementById('skipnex').onclick=function () { skip("img",0); };
    // document.getElementById('skip1').onclick=function () { skip("img",1); };
    // document.getElementById('skip2').onclick=function () { skip("img",2); };
    // document.getElementById('skip3').onclick=function () { skip("img",3); };
    // document.getElementById('skip4').onclick=function () { skip("img",4); };
    // document.getElementById('skip5').onclick=function () { skip("img",5); };



    var img1='<div class="col-sm-6 col-md-4" style="width: 282px;height: 380px;"><div class="thumbnail"><a href="#"><div style="width: 242px;height: 200px;"><img onclick="getimg(';
    var img2=')" src="/';
    var img3='"></div></a><div class="caption"><h3>';
    var img4='</h3><p>';
    var img5='</p><p><a id="collect';
    var img6='" href="#" class="btn btn-default" role="button" onclick="collect(';
    var img7emp=')"><i class="glyphicon glyphicon-star-empty"></i>收藏</a> <a id="thumb';
    var img7=')"><i class="glyphicon glyphicon-star"></i>已收藏</a> <a id="thumb';
    var img8='" href="#" class="btn btn-default" role="button" onclick="thumb(';
    var img9emp=')"><i class="glyphicon glyphicon-heart-empty">点赞</i>';
    var img9=')"><i class="glyphicon glyphicon-heart">已点赞</i>';
    var img10='</a></p></div></div></div>';

    $.ajax({
        url:'/admin/getTypes.do',
        type:'get',
        contentType: false,
        processData: false,
        success:function (datas) {
            // console.log('获取类型下拉'+datas);
            // console.log('获取类型下拉'+datas.result);
            for (var i=0;i<datas.result.length;i++) {
                if (i==0) {
                    $('#imgtypes').append('<option value="' + datas.result[i]['id'] + '" selected="selected">' + datas.result[i]['name'] + '</option>');
                    $('#types').append('<li><a href="#" onclick="getImgsByType('+datas.result[i]['id']+')">'+datas.result[i]['name']+'</a></li>');
                }
                else{
                    $('#imgtypes').append('<option value="' + datas.result[i]['id'] + '">' + datas.result[i]['name'] + '</option>');
                    $('#types').append('<li><a href="#" onclick="getImgsByType('+datas.result[i]['id']+')">'+datas.result[i]['name']+'</a></li>');
                }
            }
        }
    })

    function gotoMySelf() {
        if (sessionStorage.getItem('id')==null){
            alert('请登录');
            return;
        }
        sessionStorage.setItem('page',1);
        window.location.href='mine.html';
    }

    var staticTag='';
    function mySearch2(tag) {
        staticTag=tag;
        mySearch();
    }

    function mySearch() {
        // document.getElementById('skippre').onclick=function () { skip("search",-1); };
        // document.getElementById('skipnex').onclick=function () { skip("search",0); };
        // document.getElementById('skip1').onclick=function () { skip("search",1); };
        // document.getElementById('skip2').onclick=function () { skip("search",2); };
        // document.getElementById('skip3').onclick=function () { skip("search",3); };
        // document.getElementById('skip4').onclick=function () { skip("search",4); };
        // document.getElementById('skip5').onclick=function () { skip("search",5); };

        sessionStorage.setItem('page',1);
        type='search';
        search=document.getElementById('search').value;
        if (staticTag!='')
            search=staticTag;
        if (search==''){
            $('#search').attr('placeholder','请输入内容后搜索');
            return;
        }
        $.ajax({
            url:"/hui/TestController/search.do?name="+search,
            type:"get",
            success:function (datas) {
                $('#skips').empty();
                console.log("search"+datas.result);
                skipPages(datas.result.length);
                $('#imgs').empty();
                for (var i=0;i<10;i++) {
                    if (userid!=null) {
                        $.ajax({
                            url: "/hui/TestController/checkThumbAndCollect.do?imgid=" + datas.result[i]['id'] + "&userid=" + userid,
                            type: "post",
                            async:  false,
                            contentType: false,
                            processData: false,
                            success: function (data) {
                                if (data.resMsg == '未点赞,未收藏')
                                    $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                                else if (data.resMsg == '已点赞,已收藏')
                                    $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                else if (data.resMsg == '已点赞,未收藏')
                                    $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                else
                                    $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                            },
                            error: function (datas) {
                                console.log(datas);
                            }
                        });
                    }else{
                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                    }
                }
            }
        })
    }
    function collect(imgid){
        if (userid==null){
            alert('请在登录后收藏');
            return;
        }
        $.ajax({
            url: "/hui/TestController/collect.do?imgid="+imgid+"&userid="+userid,
            type: "post",
            dataType:'json',
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success: function (data) {
                checkToken(data);
                console.log('tetstetst'+data.resMsg);
                skip(type,sessionStorage.getItem('page'));
            },
            error: function (data) {
                console.log(data);
            }
        });
    }

    function getimg(imgid){
        sessionStorage.setItem('imgid',imgid);
        $.ajax({
            url:"/hui/TestController/getImgById.do?imgid="+imgid,
            type:"get",
            success:function (data) {
                console.log(data);
                $('#imgs').empty();
                $.ajax({
                    url:"/hui/TestController/getUserById.do?userid="+data.result['userid'],
                    type:"get",
                    success:function (userdata) {
                        $.ajax({
                            url:'/hui/TestController/checkPurchase.do?userid='+userid+'&imgid='+data.result.id,
                            headers:{
                                accessToken:localStorage.getItem('accessToken')
                            },
                            success:function (datas) {
                                $.ajax({
                                    url:'/hui/TestController/getTags.do?imgid='+imgid,
                                    success:function(tagsData) {
                                        console.log(userdata);
                                        if (userdata.result == null) {
                                            if (datas.resMsg == '已购买' || uploadUserId == userid)
                                                $('#imgs').append('<div style="text-align: center;"><img src="/' + data.result['imgname'] + '" style="width: 700px;height: 600px"><a href="#" onclick=""><h3>上传人: 已删除</h3></a><button class="btn btn-info" onclick="backToMain()">返回</button></div><br><div style="text-align: center;"><a href="#"><button class="btn btn-primary btn-lg active">已购买</button></a><a href="/' + data.result['imgname'] + '"download="' + data.result['imgname'] + '"><button class="btn btn-primary btn-lg active">下载图片</button></a></div>');
                                            else
                                                $('#imgs').append('<div style="text-align: center;"><img src="/' + data.result['imgname'] + '" style="width: 700px;height: 600px"><a href="#" onclick=""><h3>上传人: 已删除</h3></a><button class="btn btn-info" onclick="backToMain()">返回</button></div><br><div style="text-align: center;"><a href="#" onclick="purchase(' + imgid + ')"><button class="btn btn-primary btn-lg active">购买图片(1积分)</button></a><a href="#" onclick="ale()"><button class="btn btn-primary btn-lg active">下载图片</button></a></div>');
                                            $('#imgs').append('<div id="tags" style="text-align: center;"><h3>标签:</h3><br></div>')
                                            for (var i = 0; i < tagsData.result.length; i++) {
                                                if (userid==null||userid != uploadUserId)
                                                    $('#tags').append('<a href="#" onclick="mySearch2(\'' + tagsData.result[i]['name'] + '\')"><span class="label label-info">' + tagsData.result[i]['name'] + '(' + tagsData.result[i]['count'] + ')</span></a>&nbsp');
                                                else
                                                    $('#tags').append('<a href="#" onclick="mySearch2(\'' + tagsData.result[i]['name'] + '\')"><span class="label label-info">' + tagsData.result[i]['name'] + '(' + tagsData.result[i]['count'] + ')</span></a><a href="#"><span class="glyphicon glyphicon-remove" onclick="delTag(' + tagsData.result[i]['id'] + ')"></span></a>&nbsp');
                                            }
                                            getComments();
                                        } else {
                                            sessionStorage.setItem('uploaduser', userdata.result['id']);
                                            var uploadUserId = sessionStorage.getItem('uploaduser');
                                            if (datas.resMsg == '已购买' || uploadUserId == userid)
                                                $('#imgs').append('<div style="text-align: center;"><img src="/' + data.result['imgname'] + '" style="width: 700px;height: 600px"><a href="#" onclick="gotoHimself(' + userdata.result['id'] + ')"><h3>上传人: ' + userdata.result['name'] + '</h3></a><button class="btn btn-info" onclick="backToMain()">返回</button></div><br><div style="text-align: center;"><a href="#"><button class="btn btn-primary btn-lg active">已购买</button></a><a href="/' + data.result['imgname'] + '"download="' + data.result['imgname'] + '"><button class="btn btn-primary btn-lg active">下载图片</button></a></div>');
                                            else
                                                $('#imgs').append('<div style="text-align: center;"><img src="/' + data.result['imgname'] + '" style="width: 700px;height: 600px"><a href="#" onclick="gotoHimself(' + userdata.result['id'] + ')"><h3>上传人: ' + userdata.result['name'] + '</h3></a><button class="btn btn-info" onclick="backToMain()">返回</button></div><br><div style="text-align: center;"><a href="#" onclick="purchase(' + imgid + ')"><button class="btn btn-primary btn-lg active">购买图片(1积分)</button></a><a href="#" onclick="ale()"><button class="btn btn-primary btn-lg active">下载图片</button></a></div>');
                                            $('#imgs').append('<div id="tags" style="text-align: center;"><h3>标签:</h3><br></div>')
                                            for (var i = 0; i < tagsData.result.length; i++) {
                                                if (userid != uploadUserId)
                                                    $('#tags').append('<a href="#" onclick="mySearch2(\'' + tagsData.result[i]['name'] + '\')"><span class="label label-info">' + tagsData.result[i]['name'] + '(' + tagsData.result[i]['count'] + ')</span></a>&nbsp');
                                                else
                                                    $('#tags').append('<a href="#" onclick="mySearch2(\'' + tagsData.result[i]['name'] + '\')"><span class="label label-info">' + tagsData.result[i]['name'] + '(' + tagsData.result[i]['count'] + ')</span></a><a href="#"><span class="glyphicon glyphicon-remove" onclick="delTag(' + tagsData.result[i]['id'] + ')"></span></a>&nbsp');
                                            }
                                            getComments();
                                        }
                                    }
                                    })
                                }
                        })
                    },error:function (userdata) {
                        console.log(userdata);
                    }
                })
            },error:function (data) {
                console.log(data);
            }
        })
    }

    function delTag(tagid) {
        if (!confirm('确认删除标签?'))
            return;
        $.ajax({
            url:'/hui/TestController/delTags.do?tagid='+tagid,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success:function (data) {
                checkToken(data);
                if (data.resMsg!='删除失败'){
                    getimg(sessionStorage.getItem('imgid'));
                }else
                    alert('删除失败');
            }
        })
    }

    function addComments() {
        if (userid==null){
            alert('请在登录后发表评论');
            return;
        }
        var content=$('#content').val();
        var imgid=sessionStorage.getItem('imgid');
        if (content==''){
            alert('内容不能为空');
            return;
        }
        $.ajax({
            url:'/hui/TestController/addComments.do?userid='+userid+'&content='+content+'&imgid='+imgid,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success:function (data) {
                checkToken(data);
                if (data.resMsg!='添加失败'){
                    getComments();
                }else{
                    alert('发表失败');
                }
            }
        })
    }

    function getComments() {
        $('#rightDiv').empty();
        $('#rightDiv').append('<table id="imgs2" class="table table-hover">' +
            '</table>');
        $('#rightTitle').text('评论列表');
        var imgid = sessionStorage.getItem('imgid');
        $.ajax({
            url: '/hui/TestController/getComments.do?imgid=' + imgid,
            success: function (comments) {
                $('#imgs2').append('<tbody id="rightTable">');
                $('#rightTable').append('<tr> <td>用户</td><td>评论</td><td></td></tr>');
                console.log(comments)
                for (var i = 0; i < comments.result.length; i++) {
                    console.log('评论id:'+comments.result[i]);
                    $('#rightTable').append('<tr><td><a href="#" onclick="gotoHimself('+comments.result[i]['userid']+')"><img src="/'+comments.result[i]['pic']+'" class="img-circle" style="width: 30px;height: 30px">' + comments.result[i]['username'] + '</a></td> ' +
                        '<td>' + comments.result[i]['content'] + '</td><td><a href="#"><span class="glyphicon glyphicon-option-horizontal" onclick="comOption('+comments.result[i]['id']+','+comments.result[i]['userid']+')"></span></a><div id="commentOption'+comments.result[i]['id']+'"></div></td></tr>');
                }
                $('#rightDiv').append('<hr><div class="form-horizontal" style="border-bottom: 1px solid silver">' +
                    '            <div class="form-group">' +
                    '                <label for="pic" class="col-sm-2 control-label">内容</label>' +
                    '                <div class="col-sm-10">' +
                    '                    <input type="text" class="form-control" id="content" name="content">' +
                    '                </div>' +
                    '            </div>' +
                    '            <div class="form-group">' +
                    '                <div class="col-sm-offset-2 col-sm-10">' +
                    '                    <button class="btn btn-default" onclick="addComments()">发表</button>' +
                    '                    <h5>(注:请在登录后发表)</h5>' +
                    '                </div>' +
                    '            </div>' +
                    '        </div>')
            }
        })
    }

    function ale() {
        alert('请购买后再下载');
    }

    function purchase(imgid) {
        if (userid==null){
            alert('请在登录后购买');
            return;
        }
        $.ajax({
            url:'/hui/TestController/purchaseImg.do?userid='+userid+'&imgid='+imgid,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success:function (datas) {
                checkToken(datas);
                alert(datas.resMsg);
                getimg(imgid);
                $.ajax({
                    url:'/hui/TestController/getPoints.do?userid='+userid,
                    async:false,
                    success:function (datas) {
                        console.log('point:'+datas.result.point);
                        points=datas.result.point;
                        document.getElementById('userpic').innerHTML='积分:'+points+'<img class="img-circle" src="/'+userpic+'" alt="" style="width: 50px;height: 50px">';
                    }
                })
            }
        })
    }


    function gotoHimself(goid) {
        sessionStorage.setItem('goid',goid);
        sessionStorage.setItem('page',1);
        window.location.href='himself.html';
    }

        //右侧表格图片
    getrightTable();
    function getrightTable() {
        $('#rightDiv').empty();
        $('#rightDiv').append('<table id="imgs2" class="table table-hover">' +
            '</table>');
        $.ajax({
            url: "/hui/TestController/selectAllOrderByThumb.do",
            type: "get",
            contentType: false,
            processData: false,
            success: function (datas) {
                // $('#page').show();
                $('#imgs2').append('<tbody id="rightTable">');
                $('#rightTable').append('<tr> <td>编号</td> <td>类型</td> <td>标题</td><td>图片</td> <td>上传人</td> <td>点赞数</td></tr>');
                for (var i = 0; i < 9; i++) {
                    var n = parseInt(i) + 1;
                    $.ajax({
                        url: "/hui/TestController/getUserById.do?userid=" + datas.result[i]['userid'],
                        type: "get",
                        async: false,
                        success: function (data) {
                            $.ajax({
                                url: "/admin/getTypeById.do?typeid=" + datas.result[i]['typeid'],
                                type: "get",
                                async: false,
                                success: function (datat) {
                                    $('#rightTable').append('<tr><td>' + n + '</td><td>' + datat.result.name + '</td><td>' + datas.result[i]['title'] + '</td><td><a href="#" onclick="getimg(' + datas.result[i]['id'] + ')"><img class="img img-rounded" src="/' + datas.result[i]['imgname'] + '" alt="" style="width: 50px;height: 50px"></a></td><td>' + data.result['name'] + '</td><td>' + datas.result[i]['thumb'] + '</td></tr>');
                                }
                            })
                            // $('#imgs2').append('</tbody>');
                        }
                    })
                }
            },
            error: function (datas) {
                console.log(datas);
            }
        });
    }
    function backToMain(){
        skip(type,sessionStorage.getItem('page'));
    }

    // <a href="./images/'+data.result['imgname']+'"download="'+data.result['imgname']+'"></a>

    function getImgsByType(typeid){
        curtype=typeid;
        sessionStorage.setItem('page',1);
        document.getElementById('curpage').innerText=sessionStorage.getItem('page');
        $.ajax({
            url:'/admin/getTypeById.do?typeid='+typeid,
            type:'get',
            success:function (data) {
                document.getElementById('typename').innerText=data.result.name;
            }
        })
        $('#imgs').empty();
        $.ajax({
            url: "/hui/TestController/getImgsByType.do?typeid="+typeid,
            type: "post",
            contentType: false,
            processData: false,
            success: function (datas) {
                console.log(datas);
                for (var i=0;i<10;i++) {

                    if (userid!=null) {
                        $.ajax({
                            url: "/hui/TestController/checkThumbAndCollect.do?imgid=" + datas.result[i]['id'] + "&userid=" + userid,
                            type: "post",
                            async:false,
                            contentType: false,
                            processData: false,
                            success: function (data) {
                                console.log(datas.result[i]['imgname']);
                                if (data.resMsg == '未点赞,未收藏')
                                    $('#imgs').append(img1 + datas.result[i]['id'] + img2 + datas.result[i]['imgname'] + img3 + datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                                else if (data.resMsg == '已点赞,已收藏')
                                    $('#imgs').append(img1 + datas.result[i]['id'] + img2 + datas.result[i]['imgname'] + img3 + datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                else if (data.resMsg == '已点赞,未收藏')
                                    $('#imgs').append(img1 + datas.result[i]['id'] + img2 + datas.result[i]['imgname'] + img3 + datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                else
                                    $('#imgs').append(img1 + datas.result[i]['id'] + img2 + datas.result[i]['imgname'] + img3 + datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                            },
                            error: function (datas) {
                                console.log(datas);
                            }
                        });
                    }else{
                        $('#imgs').append(img1 + datas.result[i]['id'] + img2 + datas.result[i]['imgname'] + img3 + datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                    }
                }
            },
            error: function (datas) {
                console.log(datas);
            }
        });
    }

    //初次加载页面，默认显示篮球分类图片
    $.ajax({
        url: "/hui/TestController/getImgsByType.do?typeid="+2,
        type: "post",
        contentType: false,
        processData: false,
        success: function (datas) {
            console.log(datas);
            for (var i=0;i<10;i++) {

                if (userid!=null) {
                    $.ajax({
                        url: "/hui/TestController/checkThumbAndCollect.do?imgid=" + datas.result[i]['id'] + "&userid=" + userid,
                        type: "post",
                        async:false,
                        contentType: false,
                        processData: false,
                        success: function (data) {
                                if (data.resMsg == '未点赞,未收藏')
                                    $('#imgs').append(img1 + datas.result[i]['id'] + img2 + datas.result[i]['imgname'] + img3 + datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                                else if (data.resMsg == '已点赞,已收藏')
                                    $('#imgs').append(img1 + datas.result[i]['id'] + img2 + datas.result[i]['imgname'] + img3 + datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                else if (data.resMsg == '已点赞,未收藏')
                                    $('#imgs').append(img1 + datas.result[i]['id'] + img2 + datas.result[i]['imgname'] + img3 + datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                else
                                    $('#imgs').append(img1 + datas.result[i]['id'] + img2 + datas.result[i]['imgname'] + img3 + datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                        },
                        error: function (datas) {
                            console.log(datas);
                        }
                    });
                }else{
                        $('#imgs').append(img1 + datas.result[i]['id'] + img2 + datas.result[i]['imgname'] + img3 + datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                }
            }
        },
        error: function (datas) {
            console.log(datas);
        }
    });

    function skipToPage() {
        var toPageNum=$('#toPageNum').val();
        skip(type,toPageNum);
    }

    function skip(type,flag) {
        getrightTable();
        $('#rightTitle').text('点赞排行');
        if (flag==-1)
            var page=parseInt(sessionStorage.getItem('page'))-1;
        else if (flag==0)
            var page=parseInt(sessionStorage.getItem('page'))+1;
        else
            var page=flag;
        if (page<=0)
            page=1;
        if (page>=pages)
            page=pages;

        sessionStorage.setItem('page',page);
        document.getElementById('curpage').innerText=sessionStorage.getItem('page');
        $('#toPageNum').val(page);
        if (type=='img'){
            $.ajax({
                url: "/hui/TestController/getImgsByType.do?typeid="+curtype,
                type: "post",
                contentType: false,
                processData: false,
                success: function (datas) {
                    console.log(datas);
                    $('#imgs').empty();
                    for (var i=(page-1)*10;i<page*10;i++) {

                        if (userid!=null) {
                            $.ajax({
                                url: "/hui/TestController/checkThumbAndCollect.do?imgid=" + datas.result[i]['id'] + "&userid=" + userid,
                                type: "post",
                                async:false,
                                contentType: false,
                                processData: false,
                                success: function (data) {
                                    if (data.resMsg == '未点赞,未收藏')
                                        $('#imgs').append(img1 + datas.result[i]['id'] + img2 + datas.result[i]['imgname'] + img3 + datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                                    else if (data.resMsg == '已点赞,已收藏')
                                        $('#imgs').append(img1 + datas.result[i]['id'] + img2 + datas.result[i]['imgname'] + img3 + datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                    else if (data.resMsg == '已点赞,未收藏')
                                        $('#imgs').append(img1 + datas.result[i]['id'] + img2 + datas.result[i]['imgname'] + img3 + datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                    else
                                        $('#imgs').append(img1 + datas.result[i]['id'] + img2 + datas.result[i]['imgname'] + img3 + datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                                },
                                error: function (datas) {
                                    console.log(datas);
                                }
                            });
                        }else{
                            $('#imgs').append(img1 + datas.result[i]['id'] + img2 + datas.result[i]['imgname'] + img3 + datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                        }
                    }
                },
                error: function (datas) {
                    console.log(datas);
                }
            });
        }
        if (type=='search'){
            $.ajax({
                url:"/hui/TestController/search.do?name="+search,
                type:"get",
                success:function (datas) {
                    console.log("search"+datas.result);
                    $('#imgs').empty();
                    for (var i=(page-1)*10;i<page*10;i++) {
                        if (userid!=null) {
                            $.ajax({
                                url: "/hui/TestController/checkThumbAndCollect.do?imgid=" + datas.result[i]['id'] + "&userid=" + userid,
                                type: "post",
                                async:false,
                                contentType: false,
                                processData: false,
                                success: function (data) {
                                    if (data.resMsg == '未点赞,未收藏')
                                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                                    else if (data.resMsg == '已点赞,已收藏')
                                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                    else if (data.resMsg == '已点赞,未收藏')
                                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9 + datas.result[i]['thumb'] + img10);
                                    else
                                        $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7 + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                                },
                                error: function (datas) {
                                    console.log(datas);
                                }
                            });
                        }else{
                            $('#imgs').append(img1+datas.result[i]['id']+img2+ datas.result[i]['imgname']+img3+ datas.result[i]['title'] + img4 + datas.result[i]['intro'] + img5 + datas.result[i]['id'] + img6 + datas.result[i]['id'] + img7emp + datas.result[i]['id'] + img8 + datas.result[i]['id'] + img9emp + datas.result[i]['thumb'] + img10);
                        }
                    }
                }
            })
        }
    }
    function thumb(id) {
        if (userid==null){
            alert('请在登录后点赞');
            return;
        }
        $.ajax({
            url: "/hui/TestController/thumb.do?imgid="+id+"&userid="+userid,
            type: "post",
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success: function (data) {
                checkToken(data);
                console.log(data);
                skip(type,sessionStorage.getItem('page'));
            },
            error: function (data) {
                console.log(data);
            }
        });
    }

    function upload() {
        var pic = document.getElementById("pic").files[0];
        var title = document.getElementById("title").value;
        var intro = document.getElementById("intro").value;
        var tags = document.getElementById("tags").value;
        var type=$('#imgtypes').val();

        $('#uploadEr').empty();
        $('#uploadImgEr').empty();
        $('#uploadTitleEr').empty();

        if (userid==null){
            $('#uploadEr').append('<span style="color: red">请在登录后上传</span>')
            return;
        }
        if (title==''){
            $('#uploadTitleEr').append('<span style="color:red;">请输入标题</span>')
            return;
        }
        if(pic==undefined){
            $('#uploadImgEr').append('<span style="color: red">请上传图片</span>')
            return;
        }
        // console.log(file);
        // alert(title);
        var formData = new FormData();
        formData.append('pic', pic);
        formData.append('title',title);
        formData.append('intro',intro);
        formData.append('userid',userid);
        formData.append('type',type);
        formData.append('tags',tags);
        console.log("test"+formData.get('pic'));

        $.ajax({
            url: "/hui/TestController/upload.do",
            type: "post",
            data: formData,
            contentType: false,
            processData: false,
            mimeType: "multipart/form-data",
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success: function (data) {
                checkToken(data);
                console.log(data);
                data=JSON.parse(data);
                console.log(data.resMsg);
                if (data.resMsg=='请上传文件')
                    alert('请上传图片');
                else if (data.resMsg=='上传失败')
                    alert('上传失败');
                else
                    alert('上传成功,请等待审核');
                window.location.reload();
            },
            error: function (data) {
                console.log(data);
                alert('上传失败');
            }
        });
    }

    function reg(){
        var name=document.getElementById("regName").value;
        var password=document.getElementById("regPass1").value;
        var password2=document.getElementById("regPass2").value;
        // console.log(name=='');
        $('#erRegName').empty();
        $('#erRegPass').empty();
        $('#erRegPass2').empty();
        if (name==''){
            $('#erRegName').append('<span style="color:red">用户名不能为空</span>')
            return;
        }
        if (password2!=password||password2=='null') {
            $('#erRegPass2').append('<span style="color:red">密码不一致</span>')
            return;
        }
        if (password.length<6){
            $('#erRegPass').append('<span style="color:red">密码长度不能少于6位</span>')
            return;
        }
            $.ajax({
                url : "hui/TestController/reg.do?name="+name+"&password="+password,//后台请求的数据，用的是PHP
                success : function(data) {   //如果请求成功，返回数据。
                    if (data.resMsg!="注册成功"){
                        $('#erRegName').append('<span style="color:red;">'+data.resMsg+'</span>');
                        return;
                    }
                    else {
                        alert("注册成功");
                        window.location.href = "index.html";
                    }
                },
            })
    }

    console.log('用户id存不存在:'+sessionStorage.getItem('id'))
    console.log(sessionStorage.getItem('id')==null)
    console.log(localStorage.getItem('accessToken'))
    if (sessionStorage.getItem('id')==null&&localStorage.getItem('accessToken')!=null) {
        $.ajax({
            url: "hui/TestController/login.do?",
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success: function (data) {   //如果请求成功，返回数据。
                console.log("登录:"+data);
                if (data.resMsg!='token失效') {
                    // alert("登录成功");
                    sessionStorage.setItem("id", data.result.id);
                    sessionStorage.setItem("name", data.result.name);
                    sessionStorage.setItem("pass", data.result.password);
                    sessionStorage.setItem("pic", data.result.pic);
                    window.location.href = "index.html";
                }else{
                    sessionStorage.clear();
                    localStorage.clear();
                    window.location.reload();
                }
            },
        })
    }

    function login(){
        var name=document.getElementById("name").value;
        var password=document.getElementById("password").value;
        $(document).ready(function() {
            $.ajax({
                url : "hui/TestController/login.do?name="+name+"&password="+password,//后台请求的数据，用的是PHP
                success : function(data) {   //如果请求成功，返回数据。
                    var html = "";
                    $('#erLogName').empty();
                    $('#erLogPass').empty();
                    if (data.resMsg=="该用户不存在"){
                        $('#erLogName').append('<span style="color: red">该用户不存在</span>');
                        return;
                    }
                    if (data.resMsg=="密码错误"){
                        $('#erLogPass').append('<span style="color: red">密码错误</span>');
                        return;
                    }
                    else if (data.resMsg=='封禁账号'){
                        $('#erLogName').append('<span style="color: red">该账号已被封禁</span>');
                        return;
                    }
                    else {
                        alert("登录成功");
                        localStorage.setItem('accessToken',data.accessToken);
                        sessionStorage.setItem("id", data.result.id);
                        sessionStorage.setItem("name", data.result.name);
                        sessionStorage.setItem("pass",data.result.password);
                        sessionStorage.setItem("pic",data.result.pic);
                        window.location.href = "index.html";
                    }
                },
            })
        })
    }
    function gotoAdmin() {
        sessionStorage.setItem('page',1);
        if (localStorage.getItem('adminAccessToken')!=null) {
            $.ajax({
                url: '/admin/login.do',
                headers: {
                    accessToken: localStorage.getItem('adminAccessToken')
                },
                success: function (data) {

                    if (data.resMsg != 'token失效') {
                        sessionStorage.setItem('adminName', data.result.name);
                        sessionStorage.setItem("adminPic", data.result.pic);
                        sessionStorage.setItem('adminid', data.result.id);
                        window.location.href = 'admin.html';
                    } else {
                        localStorage.removeItem('adminAccessToken');
                        window.location.href = 'adminLog.html';
                    }
                }
            })
        }else{
            window.location.href='adminLog.html';
        }
    }

    function comOption(comid,comuser) {
        var opid='commentOption'+comid;
        console.log(comid+' |'+comuser);
        if (comuser==userid) {
            console.log('进入')
            if (document.getElementById('jubao'+comid)==null) {
                $('#' + opid).append('<a id="jubao'+comid+'" onclick="addComplains('+comid+')" href="#">举报</a>|');
                $('#' + opid).append('<a href="#" onclick="delCom('+comid+')">删除</a>');
            }else{
                $('#'+opid).empty();
            }
        }else{
            if (document.getElementById('jubao'+comid)==null) {
                $('#' + opid).append('<a id="jubao'+comid+'" onclick="addComplains('+comid+')" href="#">举报</a>');
            }else{
                $('#'+opid).empty();
            }
        }
    }

    function delCom(comid) {
        if (!confirm('确认删除评论?'))
            return;
        $.ajax({
            url:'/hui/TestController/delComments.do?comid='+comid,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success:function (data) {
                checkToken(data);
                if (data.resMsg!='删除失败'){
                    getComments()
                }else {
                    alert('删除失败');
                }
            }
        })
    }

    function addComplains(comid) {
        console.log(userid);
        if (userid==null){
            alert('请登录后操作');
            return;
        }
        if (!confirm('确认举报?'))
            return;
        $.ajax({
            url:'/hui/TestController/addComplains.do?comid='+comid+'&userid='+userid,
            headers:{
                accessToken:localStorage.getItem('accessToken')
            },
            success:function (data) {
                checkToken(data);
                if (data.resMsg!='添加失败'){
                    alert('举报成功');
                }else{
                    alert('举报失败');
                }
            }
        })
    }
</script>
</html>